package net.zui;

import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import net.zui.comp.ZBaseFrame;

public class Manager {
	private static Map<String,ZBaseFrame> frameMap=new HashMap<>();
	
	public static void regFrame(ZBaseFrame frame) {
		frameMap.put(frame.getId(), frame);
	}
	
	public static void start(String frameId) {
		//UComm.showMap(Manager.class, frameMap);
		ZBaseFrame baseFrame = frameMap.get(frameId);
		if(baseFrame!=null)baseFrame.setVisible(true);
	}

	public static void hide(ZBaseFrame frame) {
		frame.setVisible(false);
		boolean visible=false;
		for(Entry<String, ZBaseFrame> f:frameMap.entrySet()) {
			if(f.getValue().isVisible())visible=true;
		}
		if(!visible) {
			for(Entry<String, ZBaseFrame> f:frameMap.entrySet()) {
				f.getValue().getInnerWindow().windowClosed(new WindowEvent(f.getValue(), WindowEvent.WINDOW_CLOSED));
			}
			System.exit(0);
		}
	}
}
